library(leaflet)
library(leaflegend)
library(sf)
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'pillar'
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'tibble'
## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
foodDrink <- opq(bbox= c(-122.367375,
47.643819,
-122.323258,
47.658698)) %>%
add_osm_feature(key = 'amenity',
value = c('restaurant', 'pub', 'cafe')) %>%
osmdata_sf() %>%
getElement('osm_points')
foodDrink <- foodDrink[!is.na(foodDrink$amenity), ]
iconSet <- awesomeIconList(
pub = makeAwesomeIcon(
icon = 'beer',
library = 'fa',
iconColor = 'gold',
markerColor = 'red',
iconRotate = 35
),
cafe = makeAwesomeIcon(
icon = 'coffee',
library = 'ion',
iconColor = '#000000',
markerColor = 'blue',
squareMarker = TRUE
),
restaurant = makeAwesomeIcon(
icon = 'cutlery',
library = 'glyphicon',
iconColor = 'rgb(192, 255, 0)',
markerColor = 'darkpurple',
spin = TRUE,
squareMarker = FALSE
)
)
leaflet(foodDrink) %>%
addTiles() %>%
addAwesomeMarkers(icon = ~iconSet[amenity],
group = ~amenity) %>%
addLegendAwesomeIcon(iconSet = iconSet,
orientation = 'horizontal',
title = htmltools::tags$div(
style = 'font-size: 20px;',
'Horizontal Legend'),
labelStyle = 'font-size: 16px;',
position = 'bottomright',
group = 'Horizontal Legend') %>%
addLegendAwesomeIcon(iconSet = iconSet,
orientation = 'vertical',
marker = FALSE,
title = htmltools::tags$div(
style = 'font-size: 20px;',
'Vertical Legend'),
labelStyle = 'font-size: 16px;',
position = 'bottomright',
group = 'Vertical Legend') %>%
addLayersControl(baseGroups = sprintf('%s Legend',
c('Horizontal', 'Vertical')),
overlayGroups = c('pub', 'cafe', 'restaurant'),
options = layersControlOptions(collapsed = FALSE))
library(htmlwidgets)
cantons_point <- st_transform(st_read("../processed_data/point_data/cantons_point.shp"), crs=4326)
## Reading layer `cantons_point' from data source
## `/Users/jorissenn/Documents/GitHub/GEO454/Data/processed_data/point_data/cantons_point.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 26 features and 3 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 2500530 ymin: 1120028 xmax: 2760229 ymax: 1286433
## Projected CRS: CH1903+ / LV95
arrowIcon <- icons(
iconUrl = "../icons/point_data/arrow.png",
iconWidth=38, iconHeight = 95,
iconAnchorX = 22, iconAnchorY = 94
)
#greenLeafIcon <- makeIcon(
# iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
# iconWidth = 38, iconHeight = 95,
# iconAnchorX = 22, iconAnchorY = 94,
# shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
# shadowWidth = 50, shadowHeight = 64,
# shadowAnchorX = 4, shadowAnchorY = 62
#)
leaflet(cantons_point) %>%
addTiles() %>%
addMarkers(icon = arrowIcon)